package com.example.ad.sdk.domain.manager

import android.content.Context
import com.example.ad.sdk.domain.ad.AdNative
import com.example.ad.sdk.domain.ad.AdSlot
import com.example.ad.sdk.domain.ad.InterstitialAd
import com.example.ad.sdk.domain.ad.SplashAd
import com.example.ad.sdk.domain.models.AdType

class AdManager {
    companion object {
        /**
         * 获取 AdManager 的单例实例。
         * 该实例是线程安全的，采用懒加载模式，首次访问时创建实例。
         */
        @JvmStatic
        val to: AdManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            AdManager()
        }
    }

    fun createNativeAd(context: Context, adSlot: AdSlot): AdNative {
        return AdFactory.createAd(context, adSlot.adType, adSlot.channel)
    }

}


class AdFactory {
    companion object {
        fun createAd(context: Context, adType: AdType, channel: String): AdNative {
            return when (adType) {
                AdType.TYPE_SPLASH -> SplashAd(context, channel)
                AdType.TYPE_REWARD_VIDEO -> InterstitialAd(context, channel)
            }
        }
    }
}